<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>APP1</title>
  </head>
  <body>
    <!-- <h2>this is index.html at port 8000</h2>
    <button id="button">发送同源请求</button>
    <button id="cross-button">发送跨域请求</button>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
      const button = document.querySelector("#button");
      const crossButton = document.querySelector("#cross-button");

			const app = axios.create({
					withCredentials: true
			})

      app.get("http://localhost:8000/login", {}).then((res) => {
        console.log(res);
      });
      // 发送同域请求
      button.onclick = function () {
        app.get("http://localhost:8000/user", {}).then((res) => {
          console.log(res);
        });
      };
      // 发送跨域请求
      crossButton.onclick = function () {
        axios({
					url: 'http://localhost:8003/app2',
					methods: 'GET',
					withCredentials: true,
				}).then((res) => {
          console.log(res);
        });
      };
    </script> -->

    <h2>this is index.html at port 8000</h2>
    <button id="button">发送同源请求</button>
    <button id="cross-button">发送跨域请求</button>
    <button id="cross-button-same">发送同源post请求</button>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
      const button = document.querySelector("#button");
      const crossButton = document.querySelector("#cross-button");
      const crossButtonSame = document.querySelector("#cross-button-same");


      axios.get("http://localhost:8000/login", {}).then((res) => {
        console.log(res);
      });

      button.onclick = function () {
        axios.get("http://localhost:8000/user", {}).then((res) => {
          console.log(res);
        });
      };

      crossButton.onclick = function () {
        axios.get('http://localhost:8003/app2', { withCredentials: true }).then((res) => {
          console.log(res);
        });
      };
      crossButtonSame.onclick = function () {
        axios.post('http://localhost:8000/user/id', { withCredentials: true }).then((res) => {
          console.log(res);
        });
      };
    </script>
  </body>
</html>